//   Copyright 2012,2013 Vaughn Vernon
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package com.saasovation.common.event.sourcing;

/**
 * 事件流ID
 */
public final class EventStreamId {

    /**
     * 流名
     */
    private String streamName;
    /**
     * 流版本
     */
    private int streamVersion;

    /**
     * 使用流名构造：事件流ID
     * @param aStreamName       流名
     */
    public EventStreamId(String aStreamName) {
        this(aStreamName, 1);
    }

    /**
     * 以下参数构造：事件流ID
     * @param aStreamName       流名
     * @param aStreamVersion    流版本
     */
    public EventStreamId(String aStreamName, int aStreamVersion) {
        super();

        this.setStreamName(aStreamName);
        this.setStreamVersion(aStreamVersion);
    }

    /**
     * 以下参数构造：事件流ID
     * @param aStreamNameSegment1   流名段1
     * @param aStreamNameSegment2   流名段2
     */
    public EventStreamId(String aStreamNameSegment1, String aStreamNameSegment2) {
        this(aStreamNameSegment1, aStreamNameSegment2, 1);
    }

    /**
     * 以下参数构造：事件流ID
     * @param aStreamNameSegment1   流名段1
     * @param aStreamNameSegment2   流名段2
     * @param aStreamVersion        流版本
     */
    public EventStreamId(String aStreamNameSegment1, String aStreamNameSegment2, int aStreamVersion) {
        this(aStreamNameSegment1 + ":" + aStreamNameSegment2, aStreamVersion);
    }

    /**
     * 获取流名
     * @return  返回字符串
     */
    public String streamName() {
        return this.streamName;
    }

    /**
     * 获取流版本
     * @return  返回整型
     */
    public int streamVersion() {
        return this.streamVersion;
    }

    /**
     * 获取带流版本
     * @param aStreamVersion    流版本
     * @return                  返回事件流ID
     */
    public EventStreamId withStreamVersion(int aStreamVersion) {
        return new EventStreamId(this.streamName(), aStreamVersion);
    }

    /**
     * 设置流名
     * @param aStreamName       流名
     */
    private void setStreamName(String aStreamName) {
        this.streamName = aStreamName;
    }

    /**
     * 设置流版本
     * @param aStreamVersion    流版本
     */
    private void setStreamVersion(int aStreamVersion) {
        this.streamVersion = aStreamVersion;
    }
}
